﻿@{
    ViewBag.Title = "UserList";
    Layout = "~/Views/Shared/_BasicLayout.cshtml";
}

<script type="text/javascript">
    $(function () {
        var rowData;
        var height = $("#divTotal").height();
        var master = $("#master").height();
        var content = parseFloat(height) - parseFloat(master) - 30;
        $("#tbList").css("height", content);
    });
</script>
<script type="text/javascript">
    $(function () {
        $("#tbList").datagrid({
            url: '/User/GetUserList',
            loadMsg: '数据加载中请稍后……',
            pagination: true,
            rownumbers: true,
            idField: "ID",
            lines: true,
            singleSelect: true,
            pageSize: 20,
            queryParams: com.serializeSearchArray("form1"),
            pageList: [20, 50, 100],
            striped: true,
            // fitColumns:true,
            columns: [[{
                field: 'ck', checkbox: true, width: 30
            },
                {
                    field: 'UserName', title: '姓名', sortable: true, width: 80, align: "center"
                    //, editor: {
                    //    type: "validatebox",
                    //    options: {
                    //        required: true
                    //    }
                    //}
                },
            {
                field: 'Sex', title: '性别', sortable: true, width: 60, align: "center",
                //editor: {
                //    type: "combobox",
                //    options: {
                //        data: StaticCombo.Gender,
                //        valueField: 'value',
                //        textField: 'text',
                //    }
                //},
                formatter: function (value, row, index) {
                    return com.getArrayText(StaticCombo.Gender, value);
                }
            },
            //{
            //    field: 'BirthDate', title: '出生日期', sortable: true, width: 120, align: "center"
            //    //, editor: {
            //    //    type: "numberbox",
            //    //    options: {
            //    //    }
            //    //}
            //},
                  {
                      field: 'AccountLogIn', title: '登录账号', sortable: true, width: 100, align: "center"
                      //, editor: {
                      //    type: "validatebox",
                      //    options: {

                      //    },

                      //}
                  },
                {
                    field: 'DepId', title: '部门', sortable: true, width: 100, align: "center",
                    //editor: {
                    //    type: "combobox",
                    //    options: {
                    //        url: '/Department/GetDepInfo',
                    //        valueField: 'value',
                    //        textField: 'text',
                    //        panelWidth: 'auto',
                    //        required: true
                    //    },
                    //},
                    formatter: function (value, row, index) {
                        return row.DepName;
                    }
                },
                                {
                                    field: 'PosId', title: '岗位', sortable: true, width: 100, align: "center",
                                    //editor: {
                                    //    type: "combobox",
                                    //    options: {
                                    //        url: '/Position/GetPosInfo',
                                    //        valueField: 'value',
                                    //        textField: 'text',
                                    //        panelWidth:'auto',
                                    //        required: true
                                    //    },
                                    //},
                                    formatter: function (value, row, index) {
                                        return row.PosName;
                                    }
                                },
                     {
                         field: 'SchoolCode', title: '所属校区/机构', sortable: true, width: 100, align: "center",
                         //editor: {
                         //    type: "combobox",
                         //    options: {
                         //        url: '/SchoolInfo/GetAllSchoolInfo',
                         //        valueField: 'value',
                         //        textField: 'text',
                         //        panelWidth: 'auto',
                         //        required: true
                         //    },
                         //},
                         formatter: function (value, row, index) {
                             var SchoolName = undefined;
                             com.ajax({
                                 url: "/SchoolInfo/GetSchoolName",
                                 data: { SchoolCode: value },
                                 async: false,
                                 success: function (data) {
                                     SchoolName = data.SchoolName;
                                 }
                             });
                             return SchoolName;
                         }
                     },
                     {
                         field: 'RoleName', title: '角色名称', align: "center"

                     },
                        {
                            field: 'E_Mail', title: '邮箱', sortable: true, width: 200, align: "center"
                            //,
                            //editor: {
                            //    type: "validatebox",
                            //    options: {
                            //    }
                            //}
                        },
                        {
                            field: 'Phone', title: '电话', sortable: true, width: 100, align: "center"
                            //, editor: {
                            //    type: "validatebox",
                            //    options: {
                            //    }
                            //}
                        },
                         {
                             field: 'UserState', title: '是否在职', sortable: true, width: 80, align: "center",
                             formatter: function (value, row, index) {
                                 return com.getArrayText(StaticCombo.UserState, value);
                             }
                         },
                          {
                              field: 'IfTeacher', title: '是否教师岗', sortable: true, width: 80, align: "center",
                              formatter: function (value, row, index) {
                                  return com.getArrayText(StaticCombo.YesorNo, value);
                              }
                          },
                         {
                             field: 'ManClerk', title: '维护人', sortable: true, width: 80, align: "center"

                         },
                          {
                              field: 'BirthDate', title: '入职时间', sortable: true, width: 150, align: "center"
                          },
                          {
                              field: 'Note', title: '备注', sortable: true, width: 200, align: "center"
                              //, editor: {
                              //    type: "textbox",
                              //    options: {

                              //    }
                              //}
                          }
            ]],
            onDblClickRow: function (rowIndex, rowData) {
                top.wrapper.addTab("查看明细信息", "/BD/User/UserDetail?action=view&ID=" + rowData.ID)
            }
        });
    })


</script>
<script type="text/javascript">
    editRow = undefined;
    editAction = undefined;
    function funcSearch() {
        var para = com.serializeSearchArray("form1");
        $("#tbList").datagrid("load", para);

    }
    function funcAdd() {
        /// alert("1");
        $.messager.confirm('确认对话框', '您确定新增用户吗？', function (r) {
            if (r) {
                com.ajax({
                    url: '/User/AddUser',
                    success: function (data) {
                        //  console.log(data);
                        if (data.state == "success") {
                            top.wrapper.addTab("添加新用户", "/BD/User/UserDetail?action=add&ID=" + data.ID);
                        }
                    },
                });
            }
        });
    }
    function funcEdit() {
        var row = $('#tbList').datagrid('getSelected');
        if (row) {
            //    console.log(row.ID);
            top.wrapper.addTab("修改用户信息", '/BD/User/UserDetail?ID=' + row.ID + '&action=edit');
        }
        else {
            com.message("information", "请至少选中一行");
        }
    }
    function funcRemove() {
        $.messager.confirm('确认对话框', '您确定删除该用户吗？', function (r) {
            if (r) {
                var rowData = $("#tbList").datagrid("getSelected");
                if (rowData) {
                    com.ajax({
                        url: '/User/DelUser',
                        data: { Id: rowData.ID },
                        success: function (data) {
                            com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); })
                        }
                    });
                }
            }
        });
    }
    //function funcReload() {
    //    $("#form1").form("reset");
    //    var para = com.serializeSearchArray("form1");
    //    $("#tbList").datagrid("load", para);
    //    funcCancel()
    //}
    //用户角色配置
    function funcAssign() {
        var row = $('#tbList').datagrid('getSelected');
        if (row) {
            $.extend(com.dialogObj, { title: "分配角色", width: 500, height: 300, href: "/Role/AssignRoleWindow" });
            $("#assignUserDiv").dialog(
               com.dialogObj
            );
            $(top.document).find("#hidId").val(row.ID);
        }
        else {
            com.message("information", "请选中一行");
        }

    }
    //用户页面链接配置
    function funcAssignLink() {
        var row = $('#tbList').datagrid('getSelected');
        if (row) {
            $.extend(com.dialogObj, { title: "分配连接权限", width: 500, height: 300, href: "/UI/BD/AssignRoleLinkWindow.aspx" });
            $("#assignUserDiv").dialog(
               com.dialogObj
            );
            $(top.document).find("#hidId").val(row.ID);
        }
        else {
            com.message("information", "请选中一行");
        }
    }
    //用户按钮配置
    function funcAssignBtn() {
        var row = $('#tbList').datagrid('getSelected');
        if (row) {
            top.wrapper.addTab("分配权限", "/UI/BD/AssignAllPerm.aspx?action=edit&type=user&Id=" + row.ID);
        }
        else {
            com.message("information", "请选中一行");
        }

    }
    function funcReset()
    {
        var row = $('#tbList').datagrid('getSelected');
        if (row) {
            $.messager.confirm('确认对话框', '您确定重置该用户的密码吗？重置后的密码为123456', function (r) {
                if (r) {
                    com.ajax({
                        url: '/User/ResetPassword',
                        data: { Id: row.ID },
                        success: function (data) {
                            com.message("information", "密码重置成功")
                        }
                    });
                }
            });
        }
        else {
            com.message("information", "请选中一行");
        }
    }
</script>
<div id="divTotal" style="height: 100%; width: 100%">
    <div style="margin:5px" id="master">
        <form id="form1">
            <input id="UserName" name="UserName" class="easyui-textbox" data-options="prompt:'姓名'" data-cp="co">
            <input id="DepName" name="DepName" class="easyui-textbox" data-options="prompt:'部门'" data-cp="co">
            <input id="SchoolName" name="SchoolName" class="easyui-textbox" data-options="prompt:'所属校区名称'" style="width:130px" data-cp="co">
            在职状态：
            <input class="easyui-combobox" id="UserState" name="UserState" data-cp="=" value="0" data-options=" valuefield:'value',textfield:'text',data:StaticCombo.UserState,panelHeight:'auto',editable:false" />
            是否教师岗：
            <input class="easyui-combobox" id="IfTeacher" name="IfTeacher" data-cp="=" data-options=" valuefield:'value',textfield:'text',data:StaticCombo.YesorNo,panelHeight:'auto',editable:false" />
        </form>
    </div>
    <table id="tbList" title="用户信息表" style="width: 100%"></table>
    <div id="assignUserDiv">
    </div>
</div>
